Count the redirection forms only for current year#653
Conversation
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthroughThis PR adds a start-of-year helper and uses it to restrict redirections/donor counts to donors created on or after January 1 of the current year in both the model and the view. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
Greptile SummaryThis PR filters the redirection forms count to only include the current year by introducing a
Confidence Score: 1/5
|
| Filename | Overview |
|---|---|
| backend/donations/models/ngos.py | Critical bug: redirections_count property passes a datetime to filter() instead of a Q object or keyword argument, which will cause a TypeError at runtime. |
| backend/donations/views/ngo_account/redirections.py | Correctly filters donor count by current year using Q(date_created__gte=january_first()) within a Count annotation. |
| backend/editions/calendar.py | Adds january_first() utility that returns a timezone-aware datetime for January 1st of the current year. Missing return type annotation unlike other functions in the file. |
Flowchart
flowchart TD
A["january_first()"] -->|"returns datetime"| B["Jan 1st of current year"]
B --> C{"Used in view (redirections.py)"}
B --> D{"Used in model (ngos.py)"}
C -->|"Q(date_created__gte=datetime)"| E["Count annotation with filter ✅"]
D -->|"filter(datetime) — no field lookup"| F["TypeError at runtime ❌"]
E --> G["NgoRedirectionsView causes list"]
F --> H["Cause.redirections_count property"]
Last reviewed commit: 3fa8417
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
backend/donations/views/ngo_account/redirections.py (1)
8-29:⚠️ Potential issue | 🟡 MinorFix import ordering to satisfy CI.
The pipeline reports the import block is unsorted. Reorder the Django ORM imports (and let the formatter handle the block).♻️ Suggested order
-from django.db.models import Count, F, OuterRef, QuerySet, Subquery, Q +from django.db.models import Count, F, OuterRef, Q, QuerySet, Subquery🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@backend/donations/views/ngo_account/redirections.py` around lines 8 - 29, The import block at the top is unsorted; reorder the Django-related imports so they are grouped and alphabetized per the project's import style (e.g., django.db.models imports: Count, F, OuterRef, QuerySet, Subquery, Q should be sorted alphabetically; django.db.models.functions JSONObject; django.http imports: Http404, HttpRequest, HttpResponseNotAllowed, QueryDict; django.shortcuts redirect; django.urls reverse, reverse_lazy; django.utils.decorators method_decorator; django.utils.translation gettext_lazy as _), then run the formatter/isort to ensure CI passes—adjust the import lines that include Count, F, OuterRef, QuerySet, Subquery, Q, JSONObject, Http404, HttpRequest, HttpResponseNotAllowed, QueryDict, redirect, reverse, reverse_lazy, method_decorator, and gettext_lazy accordingly.
🤖 Fix all issues with AI agents
Verify each finding against the current code and only fix it if needed.
In `@backend/donations/models/ngos.py`:
- Around line 582-583: The redirections_count method is passing a raw datetime
as a positional arg to donor_set.filter (invalid); update redirections_count to
call donor_set.filter with a field lookup keyword on the donor model's datetime
field (for example use the created_at field with a date or range lookup such as
created_at__date=<january_first()> or created_at__gte=<january_first()>) and
then .count(); reference the redirections_count function, donor_set.filter call,
and january_first() helper when making the change.
In `@backend/donations/views/ngo_account/redirections.py`:
- Around line 8-29: The import block at the top is unsorted; reorder the
Django-related imports so they are grouped and alphabetized per the project's
import style (e.g., django.db.models imports: Count, F, OuterRef, QuerySet,
Subquery, Q should be sorted alphabetically; django.db.models.functions
JSONObject; django.http imports: Http404, HttpRequest, HttpResponseNotAllowed,
QueryDict; django.shortcuts redirect; django.urls reverse, reverse_lazy;
django.utils.decorators method_decorator; django.utils.translation gettext_lazy
as _), then run the formatter/isort to ensure CI passes—adjust the import lines
that include Count, F, OuterRef, QuerySet, Subquery, Q, JSONObject, Http404,
HttpRequest, HttpResponseNotAllowed, QueryDict, redirect, reverse, reverse_lazy,
method_decorator, and gettext_lazy accordingly.
Fixes #650
Summary by CodeRabbit
Bug Fixes
Chores